package com.aierkeji.call.b2c.service;

import java.util.Date;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.aierkeji.call.b2c.service.AkjCallLoginService.Yzm;
import com.aierkeji.call.b2c.util.DateTimeUtils;
import com.aierkeji.call.b2c.util.ResultMapHelper;
import com.aierkeji.call.b2c.util.StringUtils;

@Service
public class AkjCallCmsApiService {

	private final Logger log = LogManager.getLogger(getClass());
	@Autowired
	private AkjCallLoginService akjCallLoginService;
	
	public Map<String, Object> getYZM(Map<String, Object> map) {
		// TODO Auto-generated method stub
		String tel = (String)map.get("tel");
		String sendTimeStr = (String)map.get("sendTime");
		String scene = (String)map.get("scene");
		if(StringUtils.checkAnyNull(tel,scene)){
			return ResultMapHelper.nullParamsResult();
		}
		Date sendTime =sendTimeStr==null?null: DateTimeUtils.converStringToDate(sendTimeStr,"yyyy-MM-dd HH:mm:ss");
		return akjCallLoginService.sendYZM(tel, sendTime, scene);
	}

	public Map<String, Object> loginByYzm(Map<String, Object> map) {
		// TODO Auto-generated method stub
		String sessionYzm = (String)map.get("sessionYZM");
		String sendTimeStr = (String)map.get("sendTime");
		String sessionTel = (String)map.get("sessionTel");
		String yzm = (String)map.get("yzm");
		String tel = (String)map.get("tel");
		Integer checkCount = (Integer)map.get("checkCount");
		if(StringUtils.checkAnyNull(sessionYzm,sendTimeStr,sessionTel,yzm,tel,sessionTel)){
			return ResultMapHelper.nullParamsResult();
		}
		Date sendTime = DateTimeUtils.converStringToDate(sendTimeStr,"yyyy-MM-dd HH:mm:ss");
		if(sendTime == null) {
			return ResultMapHelper.failure("时间格式错误");
		}
		Yzm yzmConfig = akjCallLoginService.buildYzmConfig(sessionYzm, sendTime, sessionTel, yzm, tel, checkCount);
		return akjCallLoginService.checkYZM(yzmConfig);
	}

	

}
